package com.dayu.web.controller.recovery;

import java.util.List;

import com.dayu.recovery.domain.RecoveryGoods;
import com.dayu.recovery.domain.RecoveryGoodsRes;
import com.dayu.recovery.domain.StockCheckHandleLog;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.recovery.domain.StockCheckLog;
import com.dayu.recovery.service.IStockCheckLogService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 盘库日志Controller
 * 
 * @author HK
 * @date 2022-07-01
 */
@RestController
@RequestMapping("/recovery/check-log")
public class StockCheckLogController extends BaseController
{
    @Autowired
    private IStockCheckLogService stockCheckLogService;

    /**
     * 查询盘库日志列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:check-log:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockCheckLog stockCheckLog)
    {
        startPage();
        List<StockCheckLog> list = stockCheckLogService.selectStockCheckLogList(stockCheckLog);
        return getDataTable(list);
    }

    /**
     * 导出盘库日志列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:check-log:export')")
    @Log(title = "盘库日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StockCheckLog stockCheckLog)
    {
        List<StockCheckLog> list = stockCheckLogService.selectStockCheckLogList(stockCheckLog);
        ExcelUtil<StockCheckLog> util = new ExcelUtil<StockCheckLog>(StockCheckLog.class);
        return util.exportExcel(list, "check-log");
    }

    /**
     * 获取盘库日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:check-log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stockCheckLogService.selectStockCheckLogById(id));
    }

    /**
     * 新增盘库日志
     */
    @PreAuthorize("@ss.hasPermi('recovery:check-log:add')")
    @Log(title = "盘库日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockCheckLog stockCheckLog)
    {
        return toAjax(stockCheckLogService.insertStockCheckLog(stockCheckLog));
    }

    /**
     * 修改盘库日志
     */
    @PreAuthorize("@ss.hasPermi('recovery:check-log:edit')")
    @Log(title = "盘库日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockCheckLog stockCheckLog)
    {
        return toAjax(stockCheckLogService.updateStockCheckLog(stockCheckLog));
    }

    /**
     * 删除盘库日志
     */
    @PreAuthorize("@ss.hasPermi('recovery:check-log:remove')")
    @Log(title = "盘库日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockCheckLogService.deleteStockCheckLogByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('recovery:check-log:export')")
    @Log(title = "未盘导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export/row")
    public AjaxResult exportRow(Long id) {
        List<RecoveryGoods> list = stockCheckLogService.exportGoodsList(id);
        ExcelUtil<RecoveryGoods> util = new ExcelUtil<>(RecoveryGoods.class);
        return util.exportExcel(list, "未盘数据");
    }

    //日志处理列表
    @GetMapping("/handleCheckList")
    public AjaxResult handleCheckList(StockCheckHandleLog bo) {
        return AjaxResult.success(stockCheckLogService.queryCheckHandleList(bo));
    }

    //新增日志处理
    @PostMapping("/addHandleCheck")
    public AjaxResult addHandleCheck(@RequestBody StockCheckHandleLog bo) {
        return toAjax(stockCheckLogService.addHandleCheckLog(bo));
    }
}
